<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="分销商" prop="traderaccount">
        <el-select
          v-model="queryParams.traderaccount"
          placeholder="请选择"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in statusOptions"
            :key="dict.traderName"
            :label="dict.trader"
            :value="dict.traderName"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="是否撤销" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="岗位状态"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          v-hasPermi="['operationLog:noCancel:query']"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['operationLog:noCancel:edit']"
          >一键撤销</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="postList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column width="70" type="index" label="序号" align="center" />
      <el-table-column label="订单编号" align="center" prop="sn" />
      <el-table-column label="分销商" align="center" prop="traderaccount" />
      <el-table-column label="订单状态" align="center" prop="status">
        <template slot-scope="scope">
          <p v-if="postList[scope.$index].status == 0">待付款</p>
          <p v-if="postList[scope.$index].status == 1">已付款</p>
          <p v-if="postList[scope.$index].status == 2">已撤销</p>
          <p v-if="postList[scope.$index].status == 3">已打票</p>
          <p v-if="postList[scope.$index].status == 4">已申请退款(客服)</p>
          <p v-if="postList[scope.$index].status == 5">
            退款成功(客服申请退款)
          </p>
          <p v-if="postList[scope.$index].status == 6">超时支付,已申请退款</p>
          <p v-if="postList[scope.$index].status == 7">超时支付,退款成功</p>
          <p v-if="postList[scope.$index].status == 8">已申请退款(用户)</p>
          <p v-if="postList[scope.$index].status == 9">
            退款成功(用户申请退票)
          </p>
        </template>
      </el-table-column>
      <el-table-column label="预定时间" align="center" prop="dotime">
        <template slot-scope="scope">
          <span>{{ newDate(scope.row.dotime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="班次" align="center" prop="bc" />
      <el-table-column label="出发地" align="center" prop="qczmc" />
      <el-table-column label="目的地" align="center" prop="target" />
      <el-table-column label="发车时间" align="center" prop="rq">
        <template slot-scope="scope">
          <span>{{ newDate(scope.row.rq) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="票价" align="center" prop="price1" />
      <el-table-column label="数量" align="center" prop="amount1" />
      <el-table-column label="实付金额" align="center" prop="zje" />
      <el-table-column label="在线退票" align="center" prop="bc" />
      <el-table-column label="用户名" align="center" prop="username" />
      <el-table-column label="用户手机号" align="center" prop="userphone" />
      <el-table-column label="是否撤销" align="center" prop="bc">
        <template>
          <span>待撤销</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleDelete(scope.row)"
            v-hasPermi="['operationLog:noCancel:edit']"
            >撤销</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageIndex"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getPage, querytrader, cancelOrder } from "@/api/operationLog/noCancel";
import utils from "../../js/index";
import elementIcons from "../../components/icons/element-icons";
export default {
  name: "NoCancel",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      postList: [],
      // 状态数据字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        pageIndex: 1,
        pageSize: 10,
        status: "-1",
        traderaccount: ""
      },
      status: [
        {
          value: 1,
          label: "未撤销"
        },
        {
          value: 2,
          label: "撤销失败"
        }
      ],
      // 表单参数
      form: {},
      // 撤销订单
      orderList: [],
      // 撤销订单号
      orderCode: {}
      // deletList: ""
    };
  },
  created() {
    this.getList(); //未撤销订单列表
    this.getQuerytrader(); //分销商列表
  },
  methods: {
    /** 查未撤销列表 */
    getList() {
      this.loading = true;
      getPage(this.queryParams).then(response => {
        if (response.code == 200) {
          this.postList = response.data.rows;
          this.total = response.data.total;
          this.loading = false;
        } else {
          this.$message.error(response.msg);
        }
      });
    },
    // 分销商查询
    getQuerytrader() {
      querytrader().then(response => {
        if ((response.code = 200)) {
          console.log(response);
          let all = {
            trader: "全部",
            traderName: ""
          };
          let arr = [all, ...response.data];
          this.statusOptions = arr;
          console.log(this.statusOptions);
          // this.statusOptions = response.data;
        } else {
          this.$message.error(response.msg);
        }
      });
    },
    // 取消按钮
    cancel() {
      this.reset();
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageIndex = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.sn);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
      let deletList = [];
      for (var i = 0; i < this.ids.length; i++) {
        deletList.push({ sn: this.ids[i] });
      }
      this.orderList = deletList;
    },
    /** 撤销按钮操作 */
    handleDelete(row) {
      cancelOrder(this.orderList).then(response => {
        console.log(response);
        if (response.code == 200) {
          this.getList();
        } else {
          this.$message.error(response.msg);
        }
      });
    },
    // 格式化时间
    newDate(date) {
      return utils.utils.NewDate(date);
    }
  }
};
</script>
